// import licia, { throttle } from 'miniprogram-licia'

// function sayHi() {
//   console.log('hi~~~')
// }
// const newSayHi = licia.throttle(sayHi, 1000)
// const newSayHi = throttle(sayHi, 1000)

// setInterval(() => {
//   sayHi() // 本来是100毫秒执行一次
//   newSayHi() // 用节流函数后，变成1秒执行一次
// }, 100)

Page({
  data: {
    current: 1,
    pageSize: 10,
    pageTotal: 0, // 总页数
    list: [], // 列表
  },

  getMore() {
    console.log('[ getMore ] >')

    const { current, pageTotal } = this.data

    if (current === pageTotal) return wx.utils.toast('我是有底线的~')

    // 让当前页码+1
    this.setData({
      current: this.data.current + 1,
    })

    // 重新发请求
    this.getList()
  },

  async getList() {
    const res = await wx.http({
      url: '/visitor',
      data: {
        current: this.data.current,
        pageSize: this.data.pageSize,
      },
    })

    this.setData({
      pageTotal: res.data.pageTotal,
      list: [...this.data.list, ...res.data.rows],
    })
  },

  onLoad() {
    this.getList()
  },

  goPassport(e) {
    wx.navigateTo({
      url: '/visitor_pkg/pages/passport/index?id=' + e.mark.id,
    })
  },
})
